extends Area2D

enum state {fly,attack}
var current_state = state.fly
const hurt = 100
var attack_time = 1.5
# 用于累加 delta 的变量
var elapsed_time = 0

func _ready():
	current_state = state.fly
	pass

func _process(delta):
	if current_state == state.fly:
		var new_pos = self.global_position.move_toward(Vector2(291,83),delta*100)
		self.global_position = new_pos
		
	elif current_state == state.attack:
		$Label.text = "巨人"
		elapsed_time += delta
		if elapsed_time >= attack_time:
			get_tree().current_scene.get_node("EnemyTower1").hurt(hurt)
			elapsed_time = 0
	if $Life.value <= 0:
		queue_free()
	pass

func _on_giantFei_body_entered(body):
	if body.name == "EnemyTower1":
		print_debug("切换状态")
		current_state = state.attack
	pass

func hurt(v):
	$Life.value -= v
